package com.carnation.servlet;

import java.io.Writer;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.carnation.bean.FileInfo;
import com.carnation.service.FileService;
import com.carnation.service.impl.FileServiceImpl;
import com.google.gson.Gson;

public class FileInfoServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(FileInfoServlet.class);
	
	@Override
	protected void doGet(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){
		doPost(httpServletRequest, httpServletResponse);
	}
	
	@Override
	protected void doPost(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse){
		Gson gson = new Gson();
		String catalogId = httpServletRequest.getParameter("id");
		String name = httpServletRequest.getParameter("name");
		String user = httpServletRequest.getParameter("user");
		String start = httpServletRequest.getParameter("start");
		String end = httpServletRequest.getParameter("end");
		String desc = httpServletRequest.getParameter("desc");
		String remark = httpServletRequest.getParameter("remark");
		logger.info(name + " " + user +  " " + start + " " + end+ " " + desc+ " " + remark);
		logger.info(catalogId);
		FileService fileService = new FileServiceImpl();
		List<FileInfo> list = fileService.getFileInfoListByCondition(catalogId,name,user,start,end,desc,remark);
		for(FileInfo fileInfo : list){
			System.out.println(fileInfo.getName());
		}
		try{
			httpServletResponse.setCharacterEncoding("UTF-8");
			Writer writer = httpServletResponse.getWriter();
			writer.write(gson.toJson(list));
			writer.close();
		}
		catch(Exception e){
			logger.error("写响应报文错误",e);
		}
	}
}
